package com.example.yy.zyfypt_223yy.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yy.zyfypt_223yy.R;
import com.example.yy.zyfypt_223yy.iface.RegisterListener;
import com.example.yy.zyfypt_223yy.model.RegisterModel;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{
    private TextView tv1,tv2,tv3,tv4,tv5;
    private EditText et1,et2,et3,et4,et5;
    private Button btn1,btn2;
    private RegisterModel registerModel;
    private String username="",password="",rpassword="",rname="",Tel="";//用户名密码


    RegisterListener registerListener = new RegisterListener() {
        @Override
        public void onResponse(String msg) {
            if(msg.equals("1")){
                System.out.println("result:"+msg);
                Intent intent = new Intent();
                intent.setClass(RegisterActivity.this, LoginActivity.class);
                startActivity(intent);
                finish();
            }else{
                System.out.println("result:"+msg);
            }

        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(RegisterActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        Toast.makeText(this, "用户注册", Toast.LENGTH_SHORT).show();
        init();

        Button button=(Button)findViewById(R.id.button_sign);
        button.setOnClickListener(this);
    }

    private void init() {
        tv1=(TextView)findViewById(R.id.textView3);
        tv2=(TextView)findViewById(R.id.textView4);
        tv3=(TextView)findViewById(R.id.textView5);
        tv4=(TextView)findViewById(R.id.textView6);
        tv5=(TextView)findViewById(R.id.textView7);

        et1=(EditText)findViewById(R.id.editText3);
        et2=(EditText)findViewById(R.id.editText4);
        et3=(EditText)findViewById(R.id.editText5);
        et4=(EditText)findViewById(R.id.editText6);
        et5=(EditText)findViewById(R.id.editText7);

        btn1=(Button)findViewById(R.id.button_sign);
        btn2=(Button)findViewById(R.id.button4);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
    switch (v.getId())
        {
            case R.id.button_sign:
                registerModel=new RegisterModel();
                registerModel.getResult(et1.getText().toString(),et2.getText().toString(),et5.getText().toString(),registerListener);
                break;
            case R.id.button4:
              /*  System.out.println("注册——提交");
                RegisterModel registerModel = new RegisterModel();
                registerModel.getResult(name.getText().toString(),
                        pwd.getText().toString(),
                        tel.getText().toString(),
                        registerListener);*/
                Intent intent2 = new Intent();
                intent2.setClass(RegisterActivity.this, LoginActivity.class);
                startActivity(intent2);
                break;
        }
    }
}
